package com.example.demo.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

//servlet3.0后简单的定义网址的方式
@WebServlet("/HttpImageUpload")
//指定文件上传的位置
@MultipartConfig(location="e:\\")//大小写都可以
public class HttpImageUpload extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//取出文件，根据前台请求发送的文件名name
//servlet3.0后才有的方法
        Part part=request.getPart("ooo");
//写进文件名为upload.png的文件中
        part.write("upload.png");
        response.setCharacterEncoding("UTF-8");
    }

}
